package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.mapper.auto.FinishProjectMapper;
import com.fc.v2.mapper.auto.TSysRoleUserMapper;
import com.fc.v2.mapper.auto.TsysUserMapper;
import com.fc.v2.model.auto.FinishProject;
import com.fc.v2.model.auto.FinishUpload;
import com.fc.v2.model.auto.TSysRoleUser;
import com.fc.v2.model.auto.TsysUser;
import com.fc.v2.service.FinishUploadService;
import com.fc.v2.service.SysUserService;
import com.fc.v2.util.SnowflakeIdWorker;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.*;

/**
 * 查看PDF文件Controller
 * @ClassName: FileUploadController
 * @author Archie
 * @date 2019-11-20 22:35
 */
@Api(value = "查看PDF文件")
@Controller
@RequestMapping("/PDFViewController")
public class PdfViewController extends BaseController{

    /**
     * 证书查看PDF
     * @param model
     * @return String
     * @author Archie
     */
    @ApiOperation(value = "证书查看PDF", notes = "证书查看PDF")
    @RequestMapping(value="/previewPdf/{fileName}",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    // 不返回json数据就要添加ResponseBody标签
    public void previewPdf(@PathVariable("fileName") String fileName,HttpServletRequest request,HttpServletResponse response)  {
        File file = new File("C:\\_Publish\\社科联\\生成证书\\"+fileName);
        if (file.exists()){
            byte[] data = null;
            try {
                FileInputStream input = new FileInputStream(file);
                data = new byte[input.available()];
                input.read(data);
                response.getOutputStream().write(data);
                input.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }else{
            return;
        }
    }

    /**
     * 结项文件查看PDF
     * @param model
     * @return String
     * @author Archie
     */
    @ApiOperation(value = "查看PDF", notes = "查看PDF")
    @RequestMapping(value="/filePdf/{fileName}",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    // 不返回json数据就要添加ResponseBody标签
    public void filePdf(@PathVariable("fileName") String fileName,HttpServletRequest request,HttpServletResponse response)  {
        File file = new File("C:\\_Publish\\社科联\\"+fileName);
        if (file.exists()){
            byte[] data = null;
            try {
                FileInputStream input = new FileInputStream(file);
                data = new byte[input.available()];
                input.read(data);
                response.getOutputStream().write(data);
                input.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }else{
            return;
        }
    }
}
